package fr.esiag.isidis.pdsTeam.TramCreator;

public class Tram {
	static Tram instance = null;

	private Tram() {
	}

	public static Tram getInstance() {
		if (instance == null)
			instance = new Tram();
		return instance;
	}

	byte addByte(int bit, byte x) {
		x = (byte) (x << 1);
		x = (byte) (x | bit);
		return x;
	}

	byte setByte(int val1, int val2) {
		byte b = (byte) val1;
		int n2 = Integer.toBinaryString(val2).length();
		b = (byte) (b << 4 - n2);
		String s = Integer.toBinaryString(val2);
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == '1')
				b = addByte(1, b);
			else
				b = addByte(0, b);
		}
		return b;
	}

	public byte[] setTram(int TypeSource, int idSource, int codeAlerte) {
		byte b1 = setByte(TypeSource, idSource);
		byte b2 = (byte) codeAlerte;
		byte[] t = new byte[] { b1, b2 };
		return t;
	}

}
